<template>
    <y-dialog :title="props.preview.title" v-model="props.preview.open" width="80%" top="5vh" append-to-body
        class="scrollbar">
        <el-tabs>
            <el-tab-pane v-for="(value, key) in props.preview.data"
                :label="key.substring(key.lastIndexOf('/') + 1, key.indexOf('.vm'))"
                :name="key.substring(key.lastIndexOf('/') + 1, key.indexOf('.vm'))" :key="value">
                <el-link :underline="false" icon="DocumentCopy" v-copyText="value" v-copyText:callback="copyTextSuccess"
                    style="float:right">&nbsp;复制</el-link>
                <pre>{{ value }}</pre>
            </el-tab-pane>
        </el-tabs>
    </y-dialog>
</template>

<script setup name="YCodePreview">

const props = defineProps({
    preview: {
        type: Object,
        default: function () {
            return {
                // 是否显示预览对话框
                open: false,
                // 预览对话框标题
                title: "代码预览",
                // 预览文件及内容
                data: {},
            }
        },
    }
})

/** 复制代码成功 */
function copyTextSuccess() {
    proxy.$modal.msgSuccess("复制成功");
}

</script>